<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Log in</title>

<style type="text/css">
	p {
		font-family: "BankGothic Lt BT", Geneva;
		font-size: 24px;
		color: #FFF;
	}
	
	p1 {
		font-family: "BankGothic Lt BT", Geneva;
		font-size: 14px;
		color: #FFF;
	}
	</style>
</head>
<body bgcolor="#000000">
<p>Redirecting you</p>
<p1>please wait..</p1>
</body>
</html>
<?php
include ("dbConfig.php");

$sql = "SELECT * FROM `USERS` "
       ."WHERE `userName`='".$_POST[txtUsername]."' "
        ."AND `password`='".$_POST[txtPassword]."' "
       ."LIMIT 1";
	   
	   if (  $fetched = $dbhandle->query($sql)){
				$result = $fetched->fetch(PDO::FETCH_BOTH);
		if ($result["userName"] == $_POST[txtUsername] && $result["password"] == $_POST[txtPassword]){
				$_SESSION["access"] = 'granted';
		?>
			<script type="text/javascript">;
			alert("successfully logged in, <?php echo $result['userName'];?>!");
			window.location.href='http://manning3.jcu.edu.au/~jc192699/index.php';
			</script>
            <?php
		}
		
		else{
			?>
            <script type="text/javascript">;
			alert("Could not log you in! Wrong user name/password. Please try again!");
			history.back();
			</script>
            <?php		
		}
		
		}
?>